package zju.lzy.mapper;

import org.apache.ibatis.annotations.*;
import zju.lzy.dto.IOTMessage;

import java.security.Provider;
import java.util.Deque;
import java.util.List;

/**
 * @author lzy
 */
@Mapper
public interface MessageMapper {

    @Insert("insert into IOTData values (#{sender},#{clientId},#{topic},#{info},#{value},#{alert},#{lat},#{lon},#{timestamp});")
    boolean storeMessage(IOTMessage message);

    @Select("select count(*) from IOTData;")
    Integer getMessageNum();

    @Insert("<script>" +
            "insert into IOTData   VALUES " +
            "<foreach collection='list' item='item' index='index' separator=','> " +
            "(#{item.sender},#{item.clientId},#{item.topic},#{item.info},#{item.value},#{item.alert},#{item.lat},#{item.lon},#{item.timestamp}) " +
            "</foreach>" +
            "</script>")
    boolean batchStoreMessage(List<IOTMessage> list);

    @Select("select * from IOTData where sender=#{sender};")
    List<IOTMessage> getDataBySender(@Param("sender") Integer sender);

}

